<style>
  .import {
    opacity: 0;
    position: absolute;
    width: 69px;
    height: 38px;
    margin-left: -10px;
  }

  .layui-badge-rim {
    height: 20px;
    border-width: 1px;
    border-style: solid;
    background-color: #eef4f5;
    font: 14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial, sans-serif;
    color: #6e667d;
  }

  #productPic_path > img {
    max-height: 350px;
    max-width: 700px;
  }

  .material-body {
    display: flex;
    height: 100% !important;
    padding: 0 15px 0 0 !important;
  }

  .material-nav {
    width: 102px;
    background: rgba(0, 0, 0, 0.01);
  }

  .material-nav .nav-cell {
    padding: 10px 5px 10px 10px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
  }

  .material-nav .nav-cell:hover {
    color: #333;
    transition: all 0.3s;
  }

  .material-nav .nav-cell.nav-active {
    color: #333;
  }

  .material-nav .nav-cell.nav-active::before {
    content: "";
    display: inline-block;
    height: 14px;
    width: 3px;
    background: #1ba70e;
    position: absolute;
    left: 0;
  }

  .material-body .body-left {
    width: 340px;
    height: 100%;
    overflow: hidden;
  }

  .body-left .layui-tab-content {
    height: 100%;
    padding: 0;
    flex: 1;
    border-right: 1px solid #e6e6e6;
  }

  .body-left .layui-tree {
    padding: 5px;
  }

  .body-left .layui-tab {
    height: 100%;
    color: #999;
    display: flex;
    overflow: auto;
  }

  .body-left .layui-tab-title li {
    padding: 0 10px;
  }

  .material-body .body-right {
    width: calc(100% - 355px);
    padding: 15px 0 15px 15px;
  }

  .layui-tree-emptyText {
    padding-top: 5px;
  }

  .body-right xm-select {
    min-height: 32px;
    line-height: 32px;
  }

  /*.body-right .layui-table-view {*/
  /*    margin: 0;*/
  /*}*/

  /*.layui-card-body .body-right .layui-table {*/
  /*    position: relative;*/
  /*    margin: 0;*/
  /*    height: 15px;*/
  /*}*/
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body material-body">
      <!-- 头部操作栏 -->
      <div class="body-left">
        <div class="layui-tab layui-tab-brief">
          <div class="material-nav" id="materialNav"></div>
          <div class="layui-tab-content material-tree" id="productTypeTree"></div>
        </div>
      </div>
      <div class="body-right">
        <div class="layui-form lay-header" name="saleWorkOrderProcessingForm">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label">物料名称：</label>
                    <div class="layui-input-inline">
                      <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称" autocomplete="off" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">物料编码：</label>
                    <div class="layui-input-inline">
                      <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编码" autocomplete="off" />
                    </div>
                  </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true" type="button">查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows">
            <div class="lay-btn-box">
              <div class="lay-btn-lt">
                <!--                            <a id="productBtnAdd" class="layui-btn icon-btn color-reseda">添加产品/物资信息</a>-->
                <a id="productDetailBtnAdd" class="layui-btn icon-btn color-reseda">添加物资信息</a>
                <button id="productDetailBtnImport" class="layui-btn icon-btn color-reseda">
                  <input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx" />导入
                </button>
              </div>
              <div class="lay-btn-rt">
                <button id="productDetailBtnTemplate" class="layui-btn icon-btn color-green">模板下载</button>
              </div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table img-table" id="productDetailTable" lay-filter="productDetailTable"></table>
      </div>
    </div>
  </div>
</div>

<style>
  form[lay-filter="productAddForm"] .tdInputOne > input {
    display: inline-block;
    width: 30%;
  }

  form[lay-filter="productAddForm"] .tdSelectOne > .layui-form-select {
    width: 19%;
    display: inline-block;
    margin-bottom: 5px;
    margin-right: 5px;
  }

  form[lay-filter="productAddForm"] .inputBorderNone {
    border-color: transparent;
    outline-color: transparent;
  }

  form[lay-filter="productAddForm"] .inputBorderNone:hover {
    border-color: transparent !important;
    outline-color: transparent;
  }

  form[lay-filter="productAddForm"] .inputBorderNone:focus {
    border-color: transparent !important;
    outline-color: transparent;
  }

  div[lay-id="productDetailTable"] .layui-table-body .layui-table-cell {
    height: 32px;
    line-height: 32px;
  }

  .layui-form-label.w-120 {
    width: 120px;
  }

  .layui-col-md4 {
    margin-bottom: 10px;
  }

  .layui-form-label.w-150 {
    width: 150px;
  }
</style>

<script type="text/html" id="materialNavTemplate">
  {{# layui.each(d, function(index, item){ }}
  <div class="nav-cell {{# if(item.isShow){ }}nav-active{{# } }}" data-value="{{item.labelValue}}"><span>{{item.labelName}}</span></div>
  {{# }); }}
</script>
<!-- 表格操作列 -->
<script type="text/html" id="productDetailTableBar">
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="benManager">基准书</a>
</script>

<!-- 表单弹窗 -->

<!--添加产品-->
<script type="text/html" id="productAddForm">
  <!-- 表格 -->
  <table class="layui-table img-table" id="productDetailAddTable" lay-filter="productDetailAddTable"></table>
  <div class="layui-form-item text-right">
      <button class="layui-btn" type="button" lay-filter='productAddSubmit' lay-submit>提交</button>
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
  </div>
  </form>
</script>

<!--产品系列列表-->
<script type="text/html" id="productRangeList">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <form class="layui-form toolbar" lay-filter="productRangeList">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">系列名称：</label>
              <div class="layui-input-inline">
                <input name="name" class="layui-input" type="text" />
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="productRangeListSearchLog" lay-submit type="button">搜索</button>
              <button id="productRangeListAddClose" class="layui-btn icon-btn" type="button">确认选择</button>
            </div>
          </div>
        </form>

        <!-- 表格 -->
        <table class="layui-table" id="productRangeListTable" lay-filter="productRangeListTable"></table>

        <!--<div class="layui-form-item text-right">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                    <button class="layui-btn" lay-filter="productFormSubmit" lay-submit>保存</button>
                </div>-->
      </div>
    </div>
  </div>
</script>
<!-- 数据同步到云端表单弹窗 -->
<script type="text/html" id="syncSkuForm">
  <form lay-filter="synsSkuForm" class="layui-form model-form formBg" style="padding:20px;">
    <div class="layui-card-body">
      <input type="hidden" name="enterpriseCode" id="enterpriseCode" value="" />
      <div class="layui-row">
        <div class="layui-col-md4 conentStyle">
          <div class="conentBg">
            <div class="layui-form-item">
              <label class="layui-form-label w-120">企业产品系列图片:</label>
              <div class="layui-input-inline">
                <input type="hidden" name="enterpriseItemPic" id="enterpriseItemPic" value="" />
                <img src="" style="height: 135px;width: 135px" id="enterpriseItemPicImg" />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">企业产品系列名称:</label>
              <div class="layui-input-inline">
                <input name="enterpriseName" id="enterpriseName" class="layui-input borderNone" type="text" disabled />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">企业产品编码</label>
              <div class="layui-input-inline">
                <input name="enterpriseProductCode" id="enterpriseProductCode" class="layui-input borderNone" type="text" disabled />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">企业产品类型</label>
              <div class="layui-input-inline">
                <input name="enterpriseProductType" id="enterpriseProductType" class="layui-input borderNone" type="text" disabled />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">企业产品分类</label>
              <div class="layui-input-inline">
                <input name="enterpriseProductCategory" id="enterpriseProductCategory" class="layui-input borderNone" type="text" disabled />
              </div>
            </div>
            <!--<div class="layui-form-item">
                            <label class="layui-form-label w-120">企业产品扩展分类</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseProductCategoryExt" id="enterpriseProductCategoryExt"
                                       class="layui-input borderNone" type="text" disabled/>
                            </div>
                        </div>-->
          </div>
        </div>
        <div class="layui-col-md8 conentStyle">
          <div class="conentBg">
            <div class="layui-form-item">
              <label class="layui-form-label w-120">平台产品系列图片:</label>
              <div class="layui-input-inline">
                <input type="hidden" name="pictureSynsInput" id="pictureSynsInput" value="" />
                <img src="" style="height: 135px;width: 135px" id="pictureSyns" />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">平台产品系列名称</label>
              <div class="layui-input-inline">
                <input id="platformName" placeholder="请输入平台产品系列" name="platformName" class="layui-input" lay-search />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">平台产品编码</label>
              <div class="layui-input-inline">
                <input name="platformProductCode" id="platformProductCode" class="layui-input" type="text" placeholder="请输入平台产品系列" disabled />
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">平台产品类型</label>
              <div class="layui-input-inline">
                <input id="platformProductTypeId" type="hidden" />
                <select name="platformProductType" id="platformProductType" class="layui-input" type="text"></select>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label w-120">平台产品分类</label>
              <div class="layui-input-inline">
                <select name="platformProductCategory" id="platformProductCategory" class="layui-input" type="text"></select>
              </div>
            </div>
            <!-- <div class="layui-form-item">
                             <label class="layui-form-label w-120">平台产品扩展分类</label>
                             <div class="layui-input-inline">
                             <input name="platformProductCategoryExt" id="platformProductCategoryExt" class="layui-input"
                                    type="text" disabled/>
                             </div>
                         </div>-->
            <!--<div class="layui-form-item">
                            <label class="layui-form-label w-120">平台产品属性</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline mr0" id="platformProductAttrHtml"
                                     name="platformProductAttrHtml"></div>
                                <div id="platformProductAttrValueHtml" name="platformProductAttrValueHtml"></div>
                            </div>
                        </div>-->
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <input type="hidden" name="enterpriseCode" id="enterpriseDetailCode" value="" />
        <div class="layui-row">
          <div class="layui-col-md4 conentStyle">
            <div class="conentBg">
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品图片:</label>
                <div class="layui-input-inline">
                  <input type="hidden" name="enterpriseProductDetailPic" id="enterpriseProductDetailPic" value="" />
                  <img src="" style="height: 80px;width: 80px" id="enterpriseProductDetailPicImg" />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品名称:</label>
                <div class="layui-input-inline">
                  <input name="enterpriseDetailName" id="enterpriseDetailName" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品编码</label>
                <div class="layui-input-inline">
                  <input name="enterpriseProductDetailCode" id="enterpriseProductDetailCode" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业品牌</label>
                <div class="layui-input-inline">
                  <input name="enterpriseProductDetailBrand" id="enterpriseProductDetailBrand" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品单位</label>
                <div class="layui-input-inline">
                  <input name="enterpriseProductDetailUnit" id="enterpriseProductDetailUnit" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品规格码</label>
                <div class="layui-input-inline">
                  <input name="enterpriseSkuSpecValueNames" id="enterpriseSkuSpecValueNames" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品旧规格码</label>
                <div class="layui-input-inline">
                  <input name="enterpriseOldSpecCode" id="enterpriseOldSpecCode" class="layui-input borderNone" type="text" disabled />
                </div>
              </div>
            </div>
          </div>
          <div class="layui-col-md8 conentStyle">
            <div class="conentBg">
              <div class="layui-form-item">
                <label class="layui-form-label w-120">平台产品图片:</label>
                <div class="layui-input-inline">
                  <input type="hidden" name="platformProductDetailPic" id="platformProductDetailPic" value="" />
                  <img src="" style="height: 80px;width: 80px" id="platformItemPicImg" />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">平台产品名称</label>
                <div class="layui-input-inline">
                  <input name="platformDetailName" id="platformDetailName" class="layui-input" type="text" placeholder="请输入产品名称" />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">平台产品编码</label>
                <div class="layui-input-inline">
                  <input name="platformProductDetailCode" id="platformProductDetailCode" class="layui-input" type="text" placeholder="请输入产品编码" disabled />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">平台品牌</label>
                <div class="layui-input-inline">
                  <select name="platformProductDetailBrand" id="platformProductDetailBrand" class="layui-input" type="text"></select>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品单位</label>
                <div class="layui-input-inline">
                  <select name="platformProductDetailUnit" id="platformProductDetailUnit" class="layui-input" type="text"></select>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品规格码</label>
                <div class="layui-input-inline">
                  <input name="platformSkuSpecValueNames" id="platformSkuSpecValueNames" class="layui-input borderNone" type="text" />
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label w-120">企业产品旧规格码</label>
                <div class="layui-input-inline">
                  <input name="platformOldSpecCode" id="platformOldSpecCode" class="layui-input borderNone" type="text" />
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="layui-form-item text-right">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
          <button class="layui-btn" lay-filter="syncSubmit" lay-submit>同步</button>
        </div>
      </div>
    </div>
  </form>
</script>
<!-- 产品系列弹窗 -->
<script type="text/html" id="productForm">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">产品编号：</label>
                    <div class="layui-input-inline">
                      <input name="productCode" class="layui-input" type="text" placeholder="请输入产品编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">产品名称：</label>
                    <div class="layui-input-inline">
                      <input name="name" class="layui-input" type="text" placeholder="请产品名称" />
                    </div>
                  </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows">
            <div class="lay-btn-box">
              <div class="lay-btn-lt"></div>
              <div class="lay-btn-rt"></div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="productTable" lay-filter="productTable"></table>

        <div class="layui-form-item text-right">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
          <button class="layui-btn" lay-filter="productSubmit" lay-submit>提交</button>
        </div>
      </div>
    </div>
  </div>
</script>

<!--单独修改图片-->
<!--imgModifyForm-->
<!--<script type="text/html" id="imgModifyForm">-->
<!--    <form lay-filter="imgModifyForm" class="layui-form model-form"-->
<!--          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">-->
<!--        <div class="open-details-box" style="height: calc(100% - 75px);">-->
<!--            <div class="layui-row table-bor " style="margin-top: 15px;">-->
<!--                <div class="layui-form-item">-->
<!--                    <div id="productPic_path" class="uploadImgStyle"></div>-->
<!--                    <div id="productPicBtn" class="layui-btn" style="float: left;">-->
<!--                        <i class="layui-icon">&#xe681;</i>上传图片-->
<!--                    </div>-->
<!--                    <input name="productPic" type="hidden" class="layui-input" lay-verify="" id="productPic"/>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item text-right">-->
<!--            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>-->
<!--            <button class="layui-btn" lay-filter="imgModifyFormSubmit" lay-submit type="button">保存</button>-->
<!--        </div>-->
<!--    </form>-->
<!--</script>-->

<!--规格参数组件-->

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "upload", "tree", "laytpl"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laytpl = layui.laytpl;
    var syncProductName = "";
    var syncProductId = 0;
    $("body").delegate(".checkImg", "click", function () {
      admin.previewImg(".checkImg");
    });

    // 获取类别性质
    admin.req(
      "enterprise/dict/admin/dictLabel/list",
      {
        dictType: "sys_product_type_nature",
        requestType: "storage"
      },
      (res) => {
        if (res.code == 200 && res.data.length > 0) {
          res.data.forEach((item) => {
            item.isShow = false;
          });
          res.data[0].isShow = true;
          getProductType(res.data[0].labelValue);
          console.log("res.data", res.data);
          const list = res.data.filter((v) => v.id == 6 || v.id == 31|| v.id == 184);
          laytpl(materialNavTemplate.innerHTML).render(list, function (html) {
            $("#materialNav").html(html);
            $("#materialNav .nav-cell").click(function () {
              let val = $(this).data("value");
              $(this).addClass("nav-active").siblings().removeClass("nav-active");
              getProductType(val);
            });
          });
        }
      }
    );

    //物料类型
    function getProductType(materialNature) {
      admin.req(
        "enterprise/product/admin/productType/list",
        {
          enterprise: 0,
          limit: 99999,
          materialNature: materialNature
        },
        (res) => {
          if (res.code == 200) {
            let treeList = res.data.filter((item) => {
              return item.isDeleted;
            });
            initTree(treeList);
            // loadSelectHtml(res.data, '请选择物料类型', 'productTypeId', 'name');
          } else {
            // loadSelectHtml([], '请选择物料类型', 'productTypeId', 'name')
          }
        }
      );
    }

    function initTree(data) {
      layui.tree.render({
        elem: "#productTypeTree", //传入元素选择器
        data: formatToTree(data, "-1"),
        click: function (obj) {
          insTb.reload({ where: { productTypeId: obj.data.id }, page: { curr: 1 } }, "data");
        }
      });
    }

    function formatToTree(ary, pid, pidName = "parentId") {
      return ary
        .filter((item) => item[pidName] === pid)
        .map((item) => {
          // 通过父节点ID递归查询所有子节点
          item.children = formatToTree(ary, item.id);
          item.label = item.name;
          // item.spread = true
          return item;
        });
    }

    form.render("select");
    // 渲染表格
    var insTb = table.render({
      elem: "#productDetailTable",
      url: config.base + "enterprise/product/admin/productDetailWMS/list",
      where: { categoryType: "production" },
      toolbar: true,
      defaultToolbar: ["filter"],
      page: true,
      limit: 10,
      limits: [10, 20, 30, 40, 50, 60, 70, 80],
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号", align: "center", width: 60 },
          // , {
          //     field: 'skuName', align: 'center',
          //     templet: function (d) {
          //          if(d.productPic){
          //              return `<img style="height: 100%!important;width: 100%!important" src="${d.productPic}" alt="预览图" object-fit="fill" >` ;
          //          }else{
          //              return ''
          //          }
          //
          //     }, title: '预览图',
          //     event: 'imgClick'
          // }
          { field: "skuCode", align: "center", title: "物料编码", width: 120 },
          { field: "skuName", align: "center", title: "物料名称", width: 120 },
          { field: "skuSpec", align: "center", title: "规格码", width: 120 },
          { field: "productTypeName", align: "center", title: "物资类别", width: 120 },
          { field: "productCategoryName", align: "center", title: "自定义分类", width: 120 },
          { field: "isDeleted", align: "center", title: "状态", width: 120,templet:function(d){
            return d.isDeleted==='false'?'禁用':'启用'
          } },
          { field: "createTime", align: "center", title: "创建时间", width: 120 },
          { field: "modifierName", align: "center", title: "创建人", width: 120 },
          // , {field: 'materialNatureName', align: 'center', title: '类别性质', width: 140}
          // , {field: 'productTypeName', align: 'center', title: '所属类别', width: 140}
          // , {field: 'calculateWayName', align: 'center', title: '计量单位'}
          // , {field: 'baseUnitRate', align: 'center', title: '换算率'}
          // , {field: 'unitName', align: 'center', title: '基础单位'}
          { align: "center", toolbar: "#productDetailTableBar", title: "操作", width: 200, fixed: "right" }
        ]
      ],
      done: function () {
      }
    });

    // 工具条点击事件
    table.on("tool(productDetailTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "edit") {
        //修改
        showEditModel(data);
      } else if (obj.event === "benManager") {
        benManager(data);
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "syncSku") {
        // 同步
        syncSku(obj);
      }
    });

    //监听排序
    table.on("sort(productDetailTable)", function (obj) {
      table.reload("productDetailTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".nav-cell").removeClass("nav-active");
      layui.tree.render({
        elem: "#productTypeTree", //传入元素选择器
        data: []
      });
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
    });

    // function imgModify(data) {
    //     admin.open({
    //         type: 1,
    //         area: ["900px", "500px"],
    //         offset: '65px',
    //         title: '修改图片',
    //         content: $('#imgModifyForm').html(),
    //         success: function () {
    //             form.val('imgModifyForm', data);
    //             $('#productPic_path').html('<img class="checkImg" style="max-height:350px; max-width: 700px" src="' + data.productPic + '"/>');
    //             $('#productPicBtn').click(uploadImg('productPicBtn', 'productPic_path1', 'productPic1'));
    //             form.on('submit(imgModifyFormSubmit)', function (d) {
    //                 layer.load(2);
    //                 d.field.id = data.id;
    //                 d.field.image = d.field.productPic;
    //                 admin.req('enterprise/product/admin/productDetail/update', JSON.stringify(d.field), function (res) {
    //                     layer.closeAll('loading');
    //                     if (res.code == 200) {
    //                         layer.msg(res.msg, {icon: 1});
    //                         table.reload('productDetailTable');
    //                         layer.closeAll('page');
    //                     } else {
    //                         layer.msg(res.msg, {icon: 2});
    //                     }
    //                 }, 'PUT', true, 'application/json; charset=utf-8');
    //                 return false;
    //             })
    //         }
    //     })
    // }

    // 添加按钮点击事件
    $("#productDetailBtnAdd").click(function () {
      showEditModel();
    });

    //基准书管理
    function benManager(data) {
      data.productDetailId = data.id;
      admin.putTempData("benData", data ? data : null);
      // 展示ben的页面 显示物料类型
      admin.formOpen({
        area: "1400px",
        offset: "35px",
        title: "基准书管理",
        path: "components/product/benManager.html",
        success: function () {
          parentData.data = data;
        }
      });
    }

    // created 钩子
    // 根据所属类型productTypeId查找规格参数、属性参数、库存管理设置和计量单位 ProductTypeData:详情对象 用来回显
    // 显示编辑弹窗
    function showEditModel(data) {
      admin.formOpen({
        area: "1200px",
        offset: "65px",
        title: data ? "编辑物资信息" : "添加物资信息",
        path: "components/product/productDetailResearchForm.html",
        success: function () {
          parentData.data = data;
        }
      });
      // admin.open({
      //     type: 1,
      //     area: '1200px',
      //     offset: '65px',
      //     title: data ? '编辑产品明细' : '添加产品明细',
      //     content: $('#productDetailForm').html(),
      //     success: function () {
      //         $('#tabSpecParam').empty()
      //         $('#tabAttributeParam').empty()
      //         // $('#productPicBtn1').click(() => {
      //         imgUpload()
      //         // });
      //         if (data) {
      //             //获取产品明细
      //             admin.reqSync('enterprise/product/admin/productDetailWMS/get?productDetailId=' + data.id, {}, function (res) {
      //                 layer.closeAll('loading');
      //                 if (res.code == 200) {
      //                     // 所属类型
      //                     admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeDataForLast', null, 'productTypeIdType', res.data.productTypeId, "所属类型", "productTypeId", function (obj) {
      //                         $('#tabSpecParam').empty()
      //                         $('#tabAttributeParam').empty()
      //                         // admin.contentRmpty(['tabSpecParam','tabAttributeParam'])
      //                         let id = obj.change[0].value
      //                         xxx(id)
      //                     });
      //                     xxx(res.data.productTypeId, res.data)
      //
      //                     // admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeDataForLast', null, 'productTypeIdType', res.data.productTypeId, "所属类型", "productTypeId",)
      //                     admin.getDictList("mainCalWay", "product_unit_cal_way", res.data.mainCalWay, "主计量方式");
      //                     admin.getDictList("subCalWay", "product_unit_cal_way", res.data.subCalWay, "复制计量方式");
      //                     //物料类别性质
      //                     // admin.getDictList("materialNature", "sys_product_type_nature", res.data.materialNature, "物料类别性质");
      //                     //物料分类
      //                     admin.initDataSelect("enterprise/product/admin/productCategory/list", {limit: 9999}, "productCategoryId", res.data.productCategoryId, "自定义分类", null, null);
      //                     // //品牌
      //                     // admin.initDataSelect("enterprise/product/admin/productBrand/list", {limit: 9999}, "brandId", res.data.brandId, "品牌", null, null);
      //                     // //库存计量方式
      //                     // admin.getDictList("calculateWay", "sys_product_detail_calculate_way", res.data.calculateWay, "库存计量方式");
      //                     // //计量单位
      //                     // admin.getDictList("unitId", "sys_product_detail_calculate_unit", res.data.unitId, "计量单位");
      //                     // //基础单位
      //                     // admin.getDictList("baseUnit", "sys_product_detail_base_unit", res.data.baseUnit, "基础单位");
      //                     // //计价币种
      //                     // admin.getDictList("priceCurrency", "sys_product_detail_price_currency", res.data.priceCurrency, "计价币种");
      //                     // //是否自产产品
      //                     // admin.getDictList("selfProductStatus", "sys_yes_no", res.data.selfProductStatus, "是否自产产品");
      //                     // //产品性质
      //                     // admin.getDictList("productNature", "product_nature", res.data.productNature, "产品性质");
      //                     //成本核算
      //                     admin.getDictList("costCheckType", "product_detail_cost_check_type", res.data.costCheckType, "成本核算");
      //                     //是否可以销售
      //                     admin.getDictList("sellStatus", "sys_yes_no", res.data.sellStatus, "是否可以销售");
      //                     //是否质检
      //                     admin.getDictList("checkStatus", "sys_yes_no", res.data.checkStatus, "是否质检");
      //                     //出入库方式
      //                     admin.getDictList("exitStorageType", "product_detail_exit_storage_type", res.data.exitStorageType, "出入库方式");
      //                     //计价币种
      //                     admin.getDictList("priceCurrency", "sys_product_detail_price_currency", res.data.priceCurrency, "计价币种");
      //                     // //数据来源
      //                     // admin.getDictList("dataSource", "sys_product_detail_data_source", res.data.dataSource, "数据来源");
      //                     // //是否一物一码
      //                     // admin.getDictList("thingCodeStatus", "sys_yes_no", res.data.thingCodeStatus, "是否一物一码");
      //                     //是否批次管理
      //                     admin.getDictList("batchStatus", "sys_yes_no", res.data.batchStatus, "是否批次管理");
      //                     //是否先进先出
      //                     admin.getDictList("inoutStatus", "sys_yes_no", res.data.inoutStatus, "是否先进先出");
      //                     //是否料箱管理
      //                     admin.getDictList("boxStatus", "sys_yes_no", res.data.boxStatus, "是否料箱管理");
      //                     if(res.data.productPic){
      //                         $('#productPic').val(res.data.productPic); // Store the image URL in hidden input
      //                         $('#productPicPreview').attr('src', res.data.productPic).show(); // Show image preview
      //
      //                     }
      //
      //                     // //产品属性
      //                     // admin.getDictList("assemblyNature", "product_assembly_nature", res.data.assemblyNature, "产品属性");
      //                     // window.setTimeout(() => {
      //                     form.val('productDetailForm', res.data);
      //                     form.render("select")
      //                     //     console.log('res.data', res.data)
      //                     // }, 1000)
      //
      //
      //                 } else {
      //                     layer.msg(res.msg, {icon: 2});
      //                 }
      //             }, 'GET');
      //         } else {
      //             admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeDataForLast', null, 'productTypeIdType', null, "所属类型", "productTypeId", function (obj) {
      //                 $('#tabSpecParam').empty()
      //                 $('#tabAttributeParam').empty()
      //                 // admin.contentRmpty(['tabSpecParam','tabAttributeParam'])
      //                 let id = obj.change[0].value
      //                 xxx(id)
      //
      //             });
      //             // 成本核算
      //             admin.getDictList("costCheckType", "product_detail_cost_check_type", null, "成本核算");
      //
      //             // 计量方式
      //             admin.getDictList("mainCalWay", "product_unit_cal_way", null, "主计量方式");
      //             admin.getDictList("subCalWay", "product_unit_cal_way", null, "复制计量方式");
      //             //物料类别性质
      //             admin.getDictList("materialNature", "sys_product_type_nature", null, "物料类别性质");
      //             //所属类别
      //             admin.initDataSelect("enterprise/product/admin/productType/list", {limit: 9999}, "productTypeId", null, "所属类别", null, null);
      //             //物料分类
      //             admin.initDataSelect("enterprise/product/admin/productCategory/list", {limit: 9999}, "productCategoryId", null, "物料分类", null, null);
      //             //品牌
      //             admin.initDataSelect("enterprise/product/admin/productBrand/list", {limit: 9999}, "brandId", null, "品牌", null, null);
      //             //库存计量方式
      //             admin.getDictList("calculateWay", "sys_product_detail_calculate_way", null, "库存计量方式");
      //             //计量单位
      //             admin.getDictList("unitId", "sys_product_detail_calculate_unit", null, "计量单位");
      //             //基础单位
      //             // admin.getDictList("", "sys_product_detail_base_unit", null, "基础单位");
      //             //计价币种
      //             admin.getDictList("priceCurrency", "sys_product_detail_price_currency", null, "计价币种");
      //             //是否自产产品
      //             // admin.getDictList("selfProductStatus", "sys_yes_no", null, "是否自产产品");
      //             admin.getDictList("exitStorageType", "product_detail_exit_storage_type", null, "出入库方式");
      //
      //             let formFieldNameList =
      //                 {
      //                     selfProductStatus: '是否自产产品',
      //                     sellStatus: '是否可以销售',
      //                     thingCodeStatus: '是否一物一码',
      //                     batchStatus: '是否批次管理',
      //                     inoutStatus: '是否先进先出',
      //                     checkStatus: '是否质检',
      //                     boxStatus: '是否料箱管理'
      //
      //
      //                 }
      //             admin.getDictList(Object.keys(formFieldNameList),
      //                 "sys_yes_no", null, Object.values(formFieldNameList));
      //
      //             //产品性质
      //             admin.getDictList("productNature", "product_nature", null, "产品性质");
      //             //是否可以销售
      //             // admin.getDictList("sellStatus", "sys_yes_no", null, "是否可以销售");
      //             //数据来源
      //             admin.getDictList("dataSource", "sys_product_detail_data_source", null, "数据来源");
      //             //是否一物一码
      //             // admin.getDictList("thingCodeStatus", "sys_yes_no", null, "是否一物一码");
      //             //是否批次管理
      //             // admin.getDictList("batchStatus", "sys_yes_no", null, "是否批次管理");
      //             //是否先进先出
      //             // admin.getDictList("inoutStatus", "sys_yes_no", null, "是否先进先出");
      //             //产品属性
      //             admin.getDictList("assemblyNature", "product_assembly_nature", null, "产品属性");
      //         }
      //
      //         // 表单提交事件
      //         form.on('submit(productDetailSubmit)', function (d) {
      //             console.log('data', d.field)
      //
      //             var productDetailSpecList = []; //规格数组
      //             $("[name='tabSpecParam']").each(function () {
      //                 var id = $(this).attr('id').split('_')[1]
      //                 console.log(111, $(this).attr('id'))
      //                 productDetailSpecList.push({
      //                     productSpecId: id,
      //                     productSpecValue: $(this).val()
      //                 }); // 将值添加到数组中
      //             });
      //
      //             var productDetailAttributeList = []; // 属性数组
      //             $("[name='tabAttributeParam']").each(function () {
      //                 var id = $(this).attr('id').split('_')[1]
      //                 productDetailAttributeList.push({
      //                     productAttrId: id,
      //                     productAttrValue: $(this).val()
      //                 }); // 将值添加到数组中
      //             });
      //             let formData = {productDetailSpecList, productDetailAttributeList, ...d.field}
      //             admin.req(data ? 'enterprise/product/admin/productDetail/update' : 'enterprise/product/admin/productDetail/add', JSON.stringify(formData), function (res) {
      //                 layer.closeAll('loading');
      //                 if (res.code == 200) {
      //                     layer.msg(res.msg, {icon: 1});
      //                     table.reload('productDetailTable');
      //                     layer.closeAll('page');
      //                 } else {
      //                     layer.msg(res.msg, {icon: 2});
      //                 }
      //             }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
      //             return false;
      //         });
      //
      //     }
      // });
    }

    //查询企业信息
    var enterpriseInfo;
    admin.req(
      "enterprise/system/admin/enterpricceId/getEnterpricceIdVO",
      {},
      function (res) {
        enterpriseInfo = res.data;
      },
      "get",
      false
    );

    function syncSku(obj) {
      admin.open({
        type: 1,
        area: ["80%", "80%"],
        offset: "65px",
        title: "同步至云端",
        content: $("#syncSkuForm").html(),
        success: function () {
          var sync = false;
          var productData = null;
          //获取企业产品
          admin.reqSync(
            "enterprise/product/admin/productDetailWMS/syncList?skuCode=" + obj.data.skuCode,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                $("#enterpriseItemPicImg").attr("src", res.data.picture);
                $("#enterpriseName").val(res.data.name);
                $("#enterpriseProductCode").val(res.data.productCode);
                $("#enterpriseProductType").val(res.data.productType);
                $("#enterpriseProductCategory").val(res.data.productCategory);
                $("#enterpriseProductCategoryExt").val(res.data.enterpriseProductCategoryExt);
                $("#enterpriseDetailName").val(res.data.productDetail.productName);
                $("#enterpriseProductDetailPicImg").attr("src", res.data.productDetail.productPic);
                $("#enterpriseProductDetailCode").val(res.data.productDetail.skuCode);
                $("#enterpriseProductDetailBrand").val(res.data.productDetail.brandName);
                $("#enterpriseProductDetailUnit").val(res.data.productDetail.unitName);
                $("#enterpriseSkuSpecValueNames").val(res.data.productDetail.skuSpecValueNames);
                $("#enterpriseOldSpecCode").val(res.data.productDetail.oldSpecCode);

                $("#pictureSyns").attr("src", res.data.picture);
                $("#platformProductCode").val(enterpriseInfo.enterpriseCode + "_" + res.data.productCode);
                $("#platformName").val(res.data.name);
                $("#platformItemPicImg").attr("src", res.data.productDetail.productPic);
                $("#platformProductDetailCode").val(enterpriseInfo.enterpriseCode + "_" + res.data.productDetail.skuCode);
                $("#platformDetailName").val(res.data.productDetail.productName);
                $("#platformSkuSpecValueNames").val(res.data.productDetail.skuSpecValueNames);
                $("#platformOldSpecCode").val(res.data.productDetail.oldSpecCode);
                productData = res.data;
                //form.render();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "GET"
          );

          //获取平台产品类型
          admin.req(
            "enterprise/product/admin/productType/platformProductTypeList",
            {},
            function (res) {
              if (res.code === 200) {
                loadSelectHtml(res.data, "平台产品类型", "platformProductType", 1, "synsSkuForm");
              } else {
                loadSelectHtml([], "平台产品类型", "platformProductType", 1, "synsSkuForm");
              }
            },
            "GET"
          );

          //获取平台产品分类
          admin.req(
            "enterprise/product/admin/productCategory/platformProductCategoryList",
            {},
            function (res) {
              if (res.code === 200) {
                loadSelectHtml(res.data, "平台产品分类", "platformProductCategory", 1, "synsSkuForm");
              } else {
                loadSelectHtml([], "平台产品分类", "platformProductCategory", 1, "synsSkuForm");
              }
            },
            "GET"
          );

          //获取平台品牌
          admin.req(
            "enterprise/product/admin/productBrand/platformList",
            {},
            function (res) {
              if (res.code === 200) {
                loadSelectHtml(res.data, "平台品牌", "platformProductDetailBrand", 1, "synsSkuForm");
              } else {
                loadSelectHtml([], "平台品牌", "platformProductDetailBrand", 1, "synsSkuForm");
              }
            },
            "GET"
          );

          //获取平台产品单位
          admin.req(
            "enterprise/product/admin/productUnit/platformProductUnitList",
            {},
            function (res) {
              if (res.code === 200) {
                loadSelectHtml(res.data, "平台产品分类", "platformProductDetailUnit", 1, "synsSkuForm");
              } else {
                loadSelectHtml([], "平台产品分类", "platformProductDetailUnit", 1, "synsSkuForm");
              }
            },
            "GET"
          );

          /* admin.req('enterprise/product/admin/productDetailWMS/syncPlatformList', JSON.stringify(productData)  , function (res) {
                         layer.closeAll('loading');
                         if (res.code == 200) {
                             $("#pictureSyns").attr("src", res.data.picture);
                             $("#platformName").val(res.data.name)
                             $("#platformProductCode").val(res.data.productCode)
                             $("#platformProductType").val(res.data.productType)
                             $("#platformProductCategory").val(res.data.productCategory)
                             $("#platformProductCategoryExt").val(res.data.enterpriseProductCategoryExt)
                             $("#platformDetailName").val(res.data.productDetail.productName)
                             $("#platformItemPicImg").attr("src",res.data.productDetail.productPic)
                             $("#platformProductDetailCode").val(res.data.productDetail.skuCode)
                             $("#platformProductDetailBrand").val(res.data.productDetail.brandName)
                             $("#platformProductDetailUnit").val(res.data.productDetail.unitName)
                             sync = true;
                             //form.render();
                         } else {
                             layer.msg(res.msg, {icon: 2});
                         }
                     }, 'POST',true, 'application/json; charset=utf-8');*/

          form.on("submit(syncSubmit)", function (data) {
            console.log("syncSubmitsyncSubmit");
            productData.picture = $("#pictureSyns").val();
            productData.productCode = $("#platformProductCode").val();
            productData.name = $("#platformName").val();
            productData.productTypeId = $("#platformProductType").val();
            productData.productCategoryId = $("#platformProductCategory").val();
            productData.productDetail.productPic = $("#platformItemPicImg").val();
            productData.productDetail.skuCode = $("#platformProductDetailCode").val();
            productData.productDetail.skuName = $("#platformDetailName").val();
            productData.productDetail.skuSpecValueNames = $("#platformSkuSpecValueNames").val();
            productData.productDetail.oldSpecCode = $("#platformOldSpecCode").val();
            productData.productDetail.brandId = $("#platformProductDetailBrand").val();
            productData.productDetail.unitId = $("#platformProductDetailUnit").val();
            admin.req(
              "enterprise/product/admin/productDetailWMS/syncProduct",
              JSON.stringify(productData),
              function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST",
              true,
              "application/json; charset=utf-8"
            );
            /* layer.msg("不允许非法同步", {icon: 2});*/
            return false;
          });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/product/admin/productDetail/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    // 导出excel
    $("#productDetailBtnExport").click(function () {
      var checkRows = table.checkStatus("productDetailTable");
      if (checkRows.data.length == 0) {
        layer.msg("请选择要导出的数据", { icon: 2 });
      } else {
        table.exportFile(insTb.config.id, checkRows.data, "xls");
      }
    });

    // 添加产品/物资信息按钮点击事件
    $("#productBtnAdd").click(function () {
      showAddProduct();
    });

    //添加产品/物资信息弹窗
    function showAddProduct() {
      admin.open({
        type: 1,
        area: ["97%", "93%"],
        offset: ["35px", "35px"],
        title: "添加产品/物资信息",
        content: $("#productAddForm").html(),
        success: function () {
          //字典数据
          var dictDataList;
          admin.req(
            "enterprise/dict/admin/dictLabel/select",
            {},
            function (res) {
              dictDataList = res.data;
            },
            "get",
            false
          );

          //物料类别性质
          var materialNatureList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_type_nature") {
              materialNatureList.push(item);
            }
          });

          //所属类别
          var productTypeList;
          admin.req(
            "enterprise/product/admin/productType/list",
            { limit: 9999 },
            function (res) {
              productTypeList = res.data;
            },
            "get",
            false
          );

          //品牌
          var productBrandList;
          admin.req(
            "enterprise/product/admin/productBrand/list",
            { limit: 9999 },
            function (res) {
              productBrandList = res.data;
            },
            "get",
            false
          );

          //库存计量方式
          var calculateWayList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_calculate_way") {
              calculateWayList.push(item);
            }
          });

          //库存计量方式
          var calculateWayList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_calculate_way") {
              calculateWayList.push(item);
            }
          });
          //计量单位
          var calculateUnitList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_calculate_unit") {
              calculateUnitList.push(item);
            }
          });
          //基础单位
          var baseUnitList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_base_unit") {
              baseUnitList.push(item);
            }
          });
          //基础单位
          var baseUnitList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_base_unit") {
              baseUnitList.push(item);
            }
          });
          //计价币种
          var priceCurrencyList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_product_detail_price_currency") {
              priceCurrencyList.push(item);
            }
          });
          //是否
          var yesNoList = [];
          dictDataList.forEach((item, index) => {
            if (item.dictType === "sys_yes_no") {
              yesNoList.push(item);
            }
          });

          table.render({
            elem: "#productDetailAddTable",
            url: config.base + "enterprise/product/admin/productDetail/initAddData",
            page: false,
            cellMinWidth: 120,
            cols: [
              [
                { field: "productName", align: "center", title: "品名", edit: "text" },
                { field: "materialNumber", align: "center", title: "料号", edit: "text" },
                { field: "enterpriseShipmentNumber", align: "center", title: "企业货号", edit: "text" },
                { field: "standardBarCode", align: "center", title: "国标条码", edit: "text" },
                { field: "historyProductName", align: "center", title: "历史品名", edit: "text" },
                { field: "historyMaterialNumber", align: "center", title: "历史料号", edit: "text" },
                { field: "specCode", align: "center", title: "规格码", edit: "text" },
                {
                  field: "materialNature",
                  align: "center",
                  title: "物料类别性质",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="materialNature-select" name="materialNature">';
                    selectHtml += '<option value="" >请选择物料类别性质</option>';
                    layui.each(materialNatureList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "productType",
                  align: "center",
                  title: "所属类别",
                  width: 200,
                  templet: (d) => {
                    let selectHtml = '<select lay-filter="productType-select" name="productType">';
                    selectHtml += '<option value="" >请选择所属类别</option>';
                    layui.each(productTypeList, function (index, item) {
                      selectHtml += '<option value="' + item.id + '" >' + item.name + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "productBrand",
                  align: "center",
                  title: "品牌",
                  width: 180,
                  templet: function () {
                    let selectHtml = '<select lay-filter="productBrand-select" name="productBrand">';
                    selectHtml += '<option value="" >请选择品牌</option>';
                    layui.each(productBrandList, function (index, item) {
                      selectHtml += '<option value="' + item.id + '" >' + item.name + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "calculateWay",
                  align: "center",
                  title: "库存计量方式",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="calculateWay-select" name="calculateWay">';
                    selectHtml += '<option value="" >请选择库存计量方式</option>';
                    layui.each(calculateWayList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "calculateUnit",
                  align: "center",
                  title: "计量单位",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="calculateUnit-select" name="calculateUnit">';
                    selectHtml += '<option value="" >请选择计量单位</option>';
                    layui.each(calculateUnitList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                { field: "baseUnitRate", align: "center", title: "基础单位换算率", width: 140, edit: "text" },
                { field: "quantity", align: "center", title: "库存数", edit: "text" },
                {
                  field: "baseUnit",
                  align: "center",
                  title: "基础单位",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="baseUnit-select" name="baseUnit">';
                    selectHtml += '<option value="" >请选择基础单位</option>';
                    layui.each(baseUnitList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "baseUnitQuantity",
                  align: "center",
                  title: "基础单位库存数",
                  width: 140,
                  edit: "text"
                },
                {
                  field: "priceCurrency",
                  align: "center",
                  title: "计价币种",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="priceCurrency-select" name="priceCurrency">';
                    selectHtml += '<option value="" >请选择计价币种</option>';
                    layui.each(priceCurrencyList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "selfProductStatus",
                  align: "center",
                  title: "是否自产产品",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="selfProductStatus-select" name="selfProductStatus">';
                    selectHtml += '<option value="" >请选择是否自产产品</option>';
                    layui.each(yesNoList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                { field: "purchasePrice", align: "center", title: "采购价", edit: "text" },
                {
                  field: "sellStatus",
                  align: "center",
                  title: "是否可以销售",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="sellStatus-select" name="sellStatus">';
                    selectHtml += '<option value="" >请选择是否自产产品</option>';
                    layui.each(yesNoList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                { field: "price", align: "center", title: "单价", edit: "text" },
                { field: "taxRate", align: "center", title: "税率", edit: "text" },
                { field: "length", align: "center", title: "长度(mm)", edit: "text" },
                { field: "width", align: "center", title: "宽度(mm)", edit: "text" },
                { field: "height", align: "center", title: "高度(mm)", edit: "text" },
                { field: "weight", align: "center", title: "重量(克)", edit: "text" },
                { field: "supplierName", align: "center", title: "供应商" },
                { field: "customerProductName", align: "center", title: "客户品名", edit: "text" },
                { field: "customerMaterialNumber", align: "center", title: "客户料号", edit: "text" },
                { field: "customerSpecCode", align: "center", title: "客户规格码", edit: "text" },
                { field: "supplierProductName", align: "center", title: "供应商品名", edit: "text" },
                { field: "supplierMaterialNumber", align: "center", title: "供应商料号", edit: "text" },
                { field: "supplierSpecCode", align: "center", title: "供应商规格码", edit: "text" },
                { field: "safeStockValue", align: "center", title: "安全库存阈值", edit: "text" },
                { field: "purchaseCycle", align: "center", title: "采购周期(天)", edit: "text" },
                {
                  field: "dullTimeValue",
                  align: "center",
                  title: "呆滞时长阈值(天)",
                  width: 140,
                  edit: "text"
                },
                { field: "warrantyDay", align: "center", title: "质保期(天)", edit: "text" },
                { field: "warrantyDueTime", align: "center", title: "质保到期时间", edit: "text" },
                { field: "dataSource", align: "center", title: "数据来源", edit: "text" },
                {
                  field: "thingCodeName",
                  align: "center",
                  title: "是否一物一码",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="thingCodeName-select" name="thingCodeName">';
                    selectHtml += '<option value="" >请选择是否一物一码</option>';
                    layui.each(yesNoList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "batchName",
                  align: "center",
                  title: "是否批次管理",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="batchName-select" name="batchName">';
                    selectHtml += '<option value="" >请选择是否批次管理</option>';
                    layui.each(yesNoList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                },
                {
                  field: "inoutName",
                  align: "center",
                  title: "是否先进先出",
                  width: 200,
                  templet: function (d) {
                    let selectHtml = '<select lay-filter="inoutName-select" name="inoutName">';
                    selectHtml += '<option value="" >请选择是否先进先出</option>';
                    layui.each(yesNoList, function (index, item) {
                      selectHtml += '<option value="' + item.labelValue + '" >' + item.labelName + "</option>";
                    });
                    selectHtml += "</select>";
                    return selectHtml;
                  }
                }
              ]
            ],
            done: function (res, curr, count) {
              $(".layui-table-body, .layui-table-box, .layui-table-cell").css("overflow", "visible"); //显示高于表格
            }
          });

          //监听单元格编辑
          table.on("edit(productDetailAddTable)", function (obj) {
            var value = obj.value, //得到修改后的值
              data = obj.data, //得到所在行所有键值
              field = obj.field; //得到字段
            // layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
          });

          form.on("submit(productAddSubmit)", function (data) {
            var dataList = table.cache["productDetailAddTable"];
            console.info(dataList, 9099);
          });
        }
      });
    }

    // 上传文件
    /*
     * _elem: 上传按钮的名字,
     * pathId: 显示图片容器的名字,
     * inputId: 提交文件路径元素的名字,
     * isMultiple: 是不是多文件(单文件为空或者false,多文件true)
     *
     * */

    function imgUpload() {
      console.log(333);
      upload.render({
        elem: "#productPicBtn1",

        url: config.upload_url + "upload",
        accept: "file",
        headers: { Authorization: "Bearer " + config.getToken() },
        // acceptMime: 'image/*',
        exts: "jpg|jpeg|png|gif",
        done: function (res) {
          // On successful upload
          if (res.code === 200) {
            const url = res.data.url;
            $("#productPic").val(url); // Store the image URL in hidden input
            $("#productPicPreview").attr("src", url).show(); // Show image preview
            layer.msg("图片上传成功");
            console.log(111, res);
          } else {
            layer.msg("图片上传失败: " + res.msg);
          }
        },
        error: function () {
          // On upload failure
          layer.msg("上传失败，请重试");
        }
      });
    }

    function uploadImg(_elem, pathId, inputId, isMultiple) {
      upload.render({
        elem: "#" + _elem,
        url: config.upload_url + "upload",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            if (isMultiple == true) {
              $("#" + pathId).append('<img src="' + imagUrl + '"/>');
              $("#" + inputId).val(imagUrl);
            } else {
              $("#" + pathId).html('<img src="' + imagUrl + '"/>');
              $("#" + inputId).val(imagUrl);
            }
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        }
      });
    }

    // 渲染下拉选项
    function loadSelectHtml(data, tips, htmltarget, type, formName) {
      let html = " <option value>" + tips + "</option>";
      if (!data || data == null) {
        return;
      }
      for (let i = 0; i < data.length; i++) {
        if (type == 1) {
          html += `<option value='${data[i].id}'>${data[i].name}</option>`;
        }
      }
      $("form[lay-filter='" + formName + "'] select[name='" + htmltarget + "']").html(html);
      form.render("select");
    }

    // 模板下载
    $("#productDetailBtnTemplate").click(function () {
      window.location.href = config.base + "enterprise/product/admin/productDetailWMS/template";
    });

    //导入excel
    $("#uploaderInput").on("change", function (e) {
      layer.load(2);
      var formData = new FormData();
      var files = e.target.files;
      let that = $(this);
      formData.append("file", files[0]);
      formData.append("name", files[0].name); //这个地方可以传递多个参数
      $.ajax({
        url: config.base + "enterprise/product/admin/productDetailWMS/importExcel",
        data: formData,
        headers: { Authorization: "Bearer " + config.getToken() },
        type: "POST",
        processData: false,
        contentType: false,
        success: function (res) {
          layer.closeAll("loading");
          if (res.code == 200) {
            layer.msg(res.msg, { icon: 1 });
            layer.closeAll("page");
            setTimeout((_) => {
              location.reload();
            }, 1000);
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
          that.val("");
        }
      });
    });
  });
</script>
